from apps.system.user.baseViews import *


class UserViewSet(BaseUserViewSet):
    authentication_classes = []
    permission_classes = []

    def get_queryset(self):
        params = getRequestParams(self.request)
        _list = UserDao().findAll()
        return _list


class UserTreeViewSet(BaseUserViewSet):
    serializer_class = UserTreeModelSerializer

    def get_queryset(self):
        params = getRequestParams(self.request)
        _lists = None
        if params.get('lessee'):
            _lists = UserDao().findAllUserByLessee(params.get('lessee'))
        else:
            _lists = UserDao().findAllUser()
        parentId = params.get('parentId')
        parentCode = params.get('parentCode')
        if parentId:
            _lists = _lists.filter(parent = parentId)
        elif parentCode:
            _lists = _lists.filter(code=parentCode)
        else:
            _lists = _lists.filter(parent__isnull=True)
        return _lists.order_by('id')